﻿Public Class ProjektverwaltungAdapter
    Inherits StammdatenverwaltungAdapter(Of frmProjekteverwaltung, ProjektverwaltungListener, Projekt)

    Sub New()
        MyBase.New(New frmProjekteverwaltung)

        Me.setComboboxes(form.cbxKunde, Nothing, Nothing)

        Me.setListView(form.lsvProjekte)
        Me.setDeleteButton(form.btnLöschen)
        Me.setEditButton(form.btnBearbeiten)
        Me.setSaveButton(form.btnProjektErfassen)
        Me.addColumn("Projektname", "name", 100)

        Context.KUNDE_PROJEKT_TASK_SERVICE.getObservable.addListener(Me)
    End Sub

    ' kpt-actions:
    Public Overrides Sub onSelectedKundeChanged(ByRef kunde As Kunde)
        MyBase.onSelectedKundeChanged(kunde)
        setData(kunde.projekte)
    End Sub

    Protected Overrides Function getFormEntity(ByRef editEntity As Projekt) As Projekt
        Dim projekt As Projekt = editEntity
        If projekt Is Nothing Then
            projekt = New Projekt()
        End If
        projekt.kunde = getSelectedKunde()
        projekt.name = form.txtProjektName.Text
        Return projekt
    End Function

    Protected Overrides Sub setFormEntity(ByRef entity As Projekt)
        form.txtProjektName.Text = entity.name
    End Sub

    Protected Overrides Sub clearForm()
        form.txtProjektName.Text = ""
    End Sub
End Class
